﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BartonExtension;

namespace SqliteWrapper.Query
{
    public enum JoinMethod
    {
        Left,
        Right,
        Inner,
        Outer
    }
    public class QueryJoin
    {
        public string JoinTableName { get; set; }
        public JoinMethod Method { get; set; }
        private string JoinConditions { get; set; }

        public QueryJoin(string joinTable, JoinMethod method, string conditions)
        {
            JoinTableName = joinTable;
            Method = method;
            JoinConditions = conditions;
        }

        public string BuildSql()
        {
            string sql = "";
            switch (Method)
            {
                case JoinMethod.Left:
                    sql += "left join ";
                    break;
                case JoinMethod.Right:
                    sql += "right join ";
                    break;
                case JoinMethod.Inner:
                    sql += "inner join ";
                    break;
                case JoinMethod.Outer:
                    sql += "outer join ";
                    break;
                default:
                    break;
            }
            sql += JoinTableName;
            sql += " on {0} ".FormatWith(JoinConditions);
            return sql;
        }
    }
}
